package com.vinfai.poi;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {

	private static final String USERNAME = "BINDOC_SIPING";
	private static final String PASSWORD = "BINDOC_SIPING";
	private static final String URL = "jdbc:oracle:thin:@192.168.1.105:1521:ORCL";
	private static final String DRIVER_NAME = "oracle.jdbc.driver.OracleDriver";
	
	
	public static Connection getConnection(){
		Connection conn = null;
		try {
			Class.forName(DRIVER_NAME);
			conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public  static void close(Connection conn){
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public  static void close(ResultSet rs){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(Statement stat){
		if(stat!=null){
			try {
				stat.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void close(Connection conn,Statement stat,ResultSet rs){
		close(rs);
		close(stat);
		close(conn);
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Connection conn = getConnection();
		System.out.println(conn); 
		System.out.println("=================");
	}

}
